本文整理汇总了C#中LibraryChannel.SaveResObject方法的典型用法代码示例。如果您正苦于以下问题:C# LibraryChannel.SaveResObject方法的具体用法?C# LibraryChannel.SaveResObject怎么用?C# LibraryChannel.SaveResObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibraryChannel
的用法示例。
在下文中一共展示了LibraryChannel.SaveResObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
//.........这里部分代码省略.........
#endif
}
}
}
else
{
// 标记删除的事项,只要书目XML重新构造的时候
// 不包含其ID,书目XML保存后,就等于删除了该事项。
// 所以本函数只是简单Remove这样的listview事项即可
if (state == LineState.Deleted)
{
this.ListView.Items.Remove(item);
i--;
}
continue;
}
string strState = ListViewUtil.GetItemText(item, COLUMN_STATE);
string strID = ListViewUtil.GetItemText(item, COLUMN_ID);
string strResPath = this.BiblioRecPath + "/object/" + ListViewUtil.GetItemText(item, COLUMN_ID);
string strLocalFilename = ListViewUtil.GetItemText(item, COLUMN_LOCALPATH);
string strMime = ListViewUtil.GetItemText(item, COLUMN_MIME);
string strTimestamp = ListViewUtil.GetItemText(item, COLUMN_TIMESTAMP);
byte[] timestamp = ByteArray.GetTimeStampByteArray(strTimestamp);
byte[] output_timestamp = null;
nUploadCount++;
if (bOnlyChangeMetadata)
{
long lRet = channel.SaveResObject(
Stop,
strResPath,
"",
strLocalFilename,
strMime,
"", // range
true, // 最尾一次操作,提醒底层注意设置特殊的WebService API超时时间
timestamp,
out output_timestamp,
out strError);
timestamp = output_timestamp;
if (timestamp != null)
ListViewUtil.ChangeItemText(item,
COLUMN_TIMESTAMP,
ByteArray.GetHexTimeStampString(timestamp));
if (lRet == -1)
goto ERROR1;
Debug.Assert(timestamp != null, "");
// TODO: 出错的情况下是否要修改 timestamp 显示?是否应为非空才兑现显示
}
else
{
// 检测文件尺寸
FileInfo fi = new FileInfo(strLocalFilename);
if (fi.Exists == false)
{
strError = "文件 '" + strLocalFilename + "' 不存在...";
return -1;
}
string[] ranges = null;
示例2: UploadFile
//.........这里部分代码省略.........
RangeList rl = new RangeList(ranges[j]);
long uploaded = ((RangeItem)rl[0]).lStart;
string strPercent = "";
if (rl.Count >= 1)
{
double ratio = (double)uploaded / (double)fi.Length;
strPercent = String.Format("{0,3:N}", ratio * (double)100) + "%";
}
string strUploadedSize = GetSizeString(uploaded);
string strWaiting = "";
if (j == ranges.Length - 1)
{
strWaiting = " please wait ...";
channel.Timeout = new TimeSpan(0, 40, 0); // 40 分钟
}
else if (j > 0)
strWaiting = "剩余时间 " + ProgressEstimate.Format(_estimate.Estimate(uploaded)) + " 已经过时间 " + ProgressEstimate.Format(_estimate.delta_passed);
#if NO
if (stop != null)
stop.SetMessage( // strMessagePrefix +
"正在上载 " + ranges[j] + "/"
+ Convert.ToString(fi.Length)
+ " " + strPercent + " " + strClientFilePath + strWarning + strWaiting);
#endif
ProgressMessage(nCursorLeft, nCursorTop,
"uploading "
// + ranges[j] + "/" + Convert.ToString(fi.Length)
+ " " + strPercent + " "
+ strUploadedSize + "/" + strTotalSize + " "
// + strClientFilePath
+ strWarning + strWaiting);
int nRedoCount = 0;
REDO:
long lRet = channel.SaveResObject(
stop,
strResPath,
strClientFilePath,
strClientFilePath,
strMime,
ranges[j],
// j == ranges.Length - 1 ? true : false, // 最尾一次操作,提醒底层注意设置特殊的WebService API超时时间
timestamp,
strStyle,
out output_timestamp,
out strError);
timestamp = output_timestamp;
strWarning = "";
if (lRet == -1)
{
// 如果是第一个 chunk,自动用返回的时间戳重试一次覆盖
if (bRetryOverwiteExisting == true
&& j == 0
&& channel.ErrorCode == DigitalPlatform.LibraryClient.localhost.ErrorCode.TimestampMismatch
&& nRedoCount == 0)
{
nRedoCount++;
goto REDO;
}
if (channel.ErrorCode == DigitalPlatform.LibraryClient.localhost.ErrorCode.TimestampMismatch
&& bCharRedo == true)
{
bCharRedo = false;
goto REDO;
}
Console.WriteLine("出错: " + strError + "\r\n\r\n是否重试? (Y/N)");
ConsoleKeyInfo info = Console.ReadKey();
if (info.KeyChar == 'y' || info.KeyChar == 'Y')
{
Console.WriteLine();
nCursorLeft = Console.CursorLeft;
nCursorTop = Console.CursorTop + 2;
bCharRedo = true;
goto REDO;
}
goto ERROR1;
}
bCharRedo = false;
}
}
finally
{
channel.Timeout = old_timeout;
ProgressMessage(nCursorLeft, nCursorTop, "");
}
return 0;
ERROR1:
return -1;
}
示例3: SaveObjectFile
// 保存资源
// parameters:
// strLocalPath 打算写入 metadata 的 localpath。如果为 null 表示不使用此参数
// return:
// -1 error
// 0 发现上载的文件其实为空,不必保存了
// 1 已经保存
public static int SaveObjectFile(
LibraryChannel channel,
Stop stop,
string strResPath,
string strLocalFileName,
byte[] timestamp,
string strMime,
string strLocalPath,
out string strError)
{
strError = "";
// 检测文件尺寸
FileInfo fi = new FileInfo(strLocalFileName);
if (fi.Exists == false)
{
strError = "文件 '" + strLocalFileName + "' 不存在...";
return -1;
}
string[] ranges = null;
if (fi.Length == 0)
{ // 空文件
ranges = new string[1];
ranges[0] = "";
}
else
{
string strRange = "";
strRange = "0-" + Convert.ToString(fi.Length - 1);
// 按照100K作为一个chunk
ranges = RangeList.ChunkRange(strRange,
channel.UploadResChunkSize // 100 * 1024
);
}
byte[] output_timestamp = null;
string strLastModifyTime = DateTime.UtcNow.ToString("u");
REDOWHOLESAVE:
string strWarning = "";
for (int j = 0; j < ranges.Length; j++)
{
REDOSINGLESAVE:
if (stop != null && stop.State != 0)
{
strError = "用户中断";
return -1;
}
string strWaiting = "";
if (j == ranges.Length - 1)
strWaiting = " 请耐心等待...";
string strPercent = "";
RangeList rl = new RangeList(ranges[j]);
if (rl.Count >= 1)
{
double ratio = (double)((RangeItem)rl[0]).lStart / (double)fi.Length;
strPercent = String.Format("{0,3:N}", ratio * (double)100) + "%";
}
if (stop != null)
stop.SetMessage("正在上载 " + ranges[j] + "/"
+ Convert.ToString(fi.Length)
+ " " + strPercent + " " + strLocalFileName + strWarning + strWaiting);
long lRet = channel.SaveResObject(
stop,
strResPath,
strLocalFileName,
strLocalPath,
strMime,
ranges[j],
j == ranges.Length - 1 ? true : false, // 最尾一次操作,提醒底层注意设置特殊的WebService API超时时间
timestamp,
out output_timestamp,
out strError);
timestamp = output_timestamp;
strWarning = "";
if (lRet == -1)
{
if (channel.ErrorCode == LibraryClient.localhost.ErrorCode.TimestampMismatch)
{
//.........这里部分代码省略.........
示例4: SaveUploadFile
//.........这里部分代码省略.........
string strLastModifyTime = DateTime.UtcNow.ToString("u");
string strLocalPath = postedFile.FileName;
// page.Response.Write("<br/>正在保存" + strLocalPath);
REDOWHOLESAVE:
string strWarning = "";
for (int j = 0; j < ranges.Length; j++)
{
REDOSINGLESAVE:
// Application.DoEvents(); // 出让界面控制权
if (stop.State != 0)
{
strError = "用户中断";
goto ERROR1;
}
string strWaiting = "";
if (j == ranges.Length - 1)
strWaiting = " 请耐心等待...";
string strPercent = "";
RangeList rl = new RangeList(ranges[j]);
if (rl.Count >= 1)
{
double ratio = (double)((RangeItem)rl[0]).lStart / (double)fi.Length;
strPercent = String.Format("{0,3:N}", ratio * (double)100) + "%";
}
if (stop != null)
stop.SetMessage("正在上载 " + ranges[j] + "/"
+ Convert.ToString(fi.Length)
+ " " + strPercent + " " + strLocalFileName + strWarning + strWaiting);
// page.Response.Write("."); // 防止前端因等待过久而超时
long lRet = channel.SaveResObject(
stop,
strResPath,
strLocalFileName,
strLocalPath,
postedFile.ContentType,
ranges[j],
j == ranges.Length - 1 ? true : false, // 最尾一次操作,提醒底层注意设置特殊的WebService API超时时间
timestamp,
out output_timestamp,
out strError);
/*
long lRet = channel.DoSaveResObject(strResPath,
strLocalFileName,
strLocalPath,
postedFile.ContentType,
strLastModifyTime,
ranges[j],
j == ranges.Length - 1 ? true : false, // 最尾一次操作,提醒底层注意设置特殊的WebService API超时时间
timestamp,
out output_timestamp,
out strError);
* */
timestamp = output_timestamp;
// DomUtil.SetAttr(node, "__timestamp", ByteArray.GetHexTimeStampString(timestamp));
strWarning = "";
if (lRet == -1)
{
if (channel.ErrorCode == CirculationClient.localhost.ErrorCode.TimestampMismatch)
{
timestamp = new byte[output_timestamp.Length];
Array.Copy(output_timestamp, 0, timestamp, 0, output_timestamp.Length);
strWarning = " (时间戳不匹配, 自动重试)";
if (ranges.Length == 1 || j == 0)
goto REDOSINGLESAVE;
goto REDOWHOLESAVE;
}
goto ERROR1;
}
}
return 1; // 已经保存
ERROR1:
return -1;
}
finally
{
// 不要忘记删除临时文件
File.Delete(strLocalFileName);
}
}