Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hemei
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
hemei
Commits
04e651cd
Commit
04e651cd
authored
Sep 04, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
运行参数 使用 json保存
parent
05194008
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
33 deletions
+87
-33
BlowingFixProfileParam.cs
...lowing/FLY.Thick.Blowing/Common/BlowingFixProfileParam.cs
+12
-1
BlowingFixProfile.cs
...ick.Blowing/FLY.Thick.Blowing/Server/BlowingFixProfile.cs
+75
-32
No files found.
Project.FLY.Thick.Blowing/FLY.Thick.Blowing/Common/BlowingFixProfileParam.cs
View file @
04e651cd
...
...
@@ -8,7 +8,7 @@ using System.Text;
namespace
FLY.Thick.Blowing.Common
{
public
class
BlowingFixProfileParam
:
INotifyPropertyChanged
public
class
BlowingFixProfileParam
:
INotifyPropertyChanged
,
Misc
.
ICopiable
,
ICloneable
{
#
region
正常运行参数
...
...
@@ -70,6 +70,17 @@ namespace FLY.Thick.Blowing.Common
#
endregion
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
object
Clone
()
{
BlowingFixProfileParam
p
=
new
BlowingFixProfileParam
();
p
.
Copy
(
this
);
return
p
;
}
public
void
Copy
(
object
src
)
{
Misc
.
PropertiesManager
.
CopyTo
(
src
,
this
);
}
}
/// <summary>
...
...
Project.FLY.Thick.Blowing/FLY.Thick.Blowing/Server/BlowingFixProfile.cs
View file @
04e651cd
using
FLY.Thick.Blowing.Common
;
using
FLY.Thick.Blowing.IService
;
using
FObjBase
;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
...
...
@@ -11,33 +12,64 @@ namespace FLY.Thick.Blowing.Server
{
public
class
BlowingFixProfile
:
IBlowingFixProfileService
{
/// <summary>
/// 参数列表!!!!!
/// </summary>
BlowingProfileDBJson
profileDB
=
new
BlowingProfileDBJson
();
public
BlowingFixProfileParam
Param
{
get
;
}
=
new
BlowingFixProfileParam
();
private
string
file_path
=
"profile.json"
;
public
BlowingFixProfile
()
{
}
public
BlowingFixProfile
(
string
path
)
{
if
(
path
==
null
)
Load
()
;
else
Load
(
path
);
if
(
!
string
.
IsNullOrEmpty
(
path
)
)
file_path
=
path
;
Load
(
);
}
public
bool
Load
()
{
return
Misc
.
SaveToXmlHepler
.
Load
(
"profile.xml"
,
this
.
Param
);
}
bool
Load
(
string
path
)
{
return
Misc
.
SaveToXmlHepler
.
Load
(
path
,
this
.
Param
);
try
{
if
(
File
.
Exists
(
file_path
))
{
string
json
=
File
.
ReadAllText
(
file_path
);
profileDB
=
JsonConvert
.
DeserializeObject
<
BlowingProfileDBJson
>(
json
);
var
param
=
profileDB
.
ParamList
.
Find
((
p
)
=>
p
.
PName
==
profileDB
.
CurrentPName
);
if
(
param
!=
null
)
{
Param
.
Copy
(
param
);
}
return
true
;
}
}
catch
{
//异常,没有json 解码失败
}
return
false
;
}
bool
Save
()
{
bool
ret2
=
Misc
.
SaveToXmlHepler
.
Save
(
@"profile.xml"
,
this
.
Param
);
bool
ret1
=
Misc
.
SaveToXmlHepler
.
Save
(
@"profile\"
+
Param
.
PName
+
".xml"
,
this
.
Param
);
return
(
ret1
&&
ret2
);
try
{
File
.
WriteAllText
(
file_path
,
JsonConvert
.
SerializeObject
(
profileDB
,
Formatting
.
Indented
));
return
true
;
}
catch
{
//异常,没有json 编码失败
}
return
false
;
}
/// <summary>
...
...
@@ -46,6 +78,18 @@ namespace FLY.Thick.Blowing.Server
public
void
Apply
()
{
Save
();
profileDB
.
CurrentPName
=
Param
.
PName
;
BlowingFixProfileParam
param
=
profileDB
.
ParamList
.
Find
((
p
)
=>
p
.
PName
==
Param
.
PName
);
if
(
param
==
null
)
{
profileDB
.
ParamList
.
Add
((
BlowingFixProfileParam
)
Param
.
Clone
());
}
else
{
param
.
Copy
(
Param
);
}
Save
();
}
/// <summary>
...
...
@@ -55,20 +99,8 @@ namespace FLY.Thick.Blowing.Server
/// <param name="AsyncState"></param>
public
void
GetList
(
AsyncCBHandler
AsyncDelegate
,
object
AsyncState
)
{
DirectoryInfo
dinfo
=
new
DirectoryInfo
(
@"profile"
);
List
<
string
>
filenames
=
new
List
<
string
>();
if
(
dinfo
.
Exists
)
{
foreach
(
FileInfo
info
in
dinfo
.
GetFiles
())
{
if
(
Path
.
GetExtension
(
info
.
Name
)
==
".xml"
)
{
filenames
.
Add
(
Path
.
GetFileNameWithoutExtension
(
info
.
Name
));
}
}
}
AsyncDelegate
(
AsyncState
,
filenames
);
IEnumerable
<
string
>
names
=
from
p
in
profileDB
.
ParamList
select
p
.
PName
;
AsyncDelegate
(
AsyncState
,
names
);
}
/// <summary>
...
...
@@ -77,9 +109,7 @@ namespace FLY.Thick.Blowing.Server
/// <param name="productname"></param>
public
void
Del
(
string
productname
)
{
string
path
=
@"profile\"
+
productname
+
".xml"
;
if
(
System
.
IO
.
File
.
Exists
(
path
))
System
.
IO
.
File
.
Delete
(
path
);
profileDB
.
ParamList
.
RemoveAll
((
p
)
=>
p
.
PName
==
productname
);
}
...
...
@@ -91,9 +121,22 @@ namespace FLY.Thick.Blowing.Server
/// <param name="AsyncState"></param>
public
void
Read
(
string
productname
,
AsyncCBHandler
AsyncDelegate
,
object
AsyncState
)
{
BlowingFixProfile
p
=
new
BlowingFixProfile
(
);
p
.
Load
(
@"profile\"
+
productname
+
".xml"
);
AsyncDelegate
(
AsyncState
,
p
.
Param
);
var
p
=
profileDB
.
ParamList
.
Find
((
_p
)
=>
_p
.
PName
==
productname
);
AsyncDelegate
(
AsyncState
,
p
);
}
}
public
class
BlowingProfileDBJson
{
/// <summary>
/// 当前正在使用的产品参数
/// </summary>
public
string
CurrentPName
{
get
;
set
;
}
/// <summary>
/// 参数列表!!!!!
/// </summary>
public
List
<
BlowingFixProfileParam
>
ParamList
{
get
;
set
;
}
=
new
List
<
BlowingFixProfileParam
>();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment